package com.inno.thread.hello;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class CallableDemo implements Callable {

    private Thread thread;
    private String threadName;


    @Override
    public Integer call() throws Exception {
        System.out.println("run callable call()");
        TimeUnit.SECONDS.sleep(10);
        return 0;
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallableDemo callableDemo = new CallableDemo();
        FutureTask futureTask = new FutureTask(callableDemo);


        int threadNum = 100;
        for (int i = 0; i < threadNum; i++) {
            System.out.println("当前线程：" + Thread.currentThread().getName() + "循环变量i的值：" + i);
            if (i == 20) {
                new Thread(futureTask, "有返回值的线程").start();
            }
        }

        System.out.println("子线程的返回值：" + futureTask.get());
    }
}
